package com.java.comprehensive.arithmetic.leecode.tags.hashmap;

import java.util.*;

/**
 * @program: comprehensive-service
 *
 * @description: 存在重复元素
 *
 * @author: 窦绍飞
 *
 * @create: 2021-12-24 14:12
 **/
public class LeetCode_217 {
	public static boolean containsDuplicate(int[] nums) {
		Map<Integer, Integer> map = new HashMap<>(16);
		for (int num : nums) {
			if (map.containsKey(num)) {
				return true;
			}
			map.put(num, null);
		}
		return false;
	}

	public static boolean containsDuplicateBySet(int[] nums) {
		Set<Object> set = new HashSet<>();
		for (int num : nums) {
			set.add(num);
		}
		return set.size() < nums.length;
	}

	public static void main(String[] args) {
		int[] nums = { 1, 2, 3, 1 };
		boolean b = containsDuplicateBySet(nums);
		System.out.println(b);
	}
}
